package com.silence.ByteDance;

// 寻找最大值
public class normal_90 {
    public static int solution(int n, int[] array) {
        // Edit your code here
        int res = 0;
        for (int i = 0; i < array.length; i++) {
            int Lmax = Integer.MIN_VALUE;
            int Rmax = Integer.MIN_VALUE;
            for (int j = 0; j < array.length; j++) {
                if (L(i, j, array)) {
                    Lmax = Math.abs(Lmax - i) > Math.abs(j - i) ? j : Lmax;
                }
                if (R(i, j, array)) {
                    Rmax = Math.abs(Rmax - i) > Math.abs(j - i) ? j : Rmax;
                }
            }
            if (Lmax == Integer.MIN_VALUE) {
                Lmax = 0;
            } else {
                Lmax += 1;
            }
            if (Rmax == Integer.MIN_VALUE) {
                Rmax = 0;
            } else {
                Rmax += 1;
            }
            res = Math.max(res, (Lmax * Rmax));
        }
        return res;
    }

    public static boolean L(int i, int j, int[] array) {
        if ((j < i) && (array[j] > array[i])) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean R(int i, int k, int[] array) {
        if ((k > i) && (array[k] > array[i])) {
            return true;
        } else {
            return false;
        }
    }

    public static void main(String[] args) {
        // Add your test cases here
        System.out.println(solution(5, new int[]{5, 4, 3, 4, 5}) == 8);
        System.out.println(solution(6, new int[]{1, 3, 2, 4, 5, 6}) == 8);
        System.out.println(solution(4, new int[]{10, 20, 10, 30}) == 8);
        System.out.println(solution(7, new int[]{7, 6, 5, 4, 3, 2, 1}) == 0);
    }
}
